package com.binyuan.move.thried;

import com.binyuan.move.config.RecorderConfig;
import com.binyuan.move.service.IScreenRecorderMoveService;
import com.binyuan.move.utils.FileUtils;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SpringContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import static com.binyuan.move.thried.MouseMovementThread.SKIMMING;

@Component
public class DayStartThread {

    MouseMovementThread thread = null;
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

    public DayStartThread(MouseMovementThread thread) {
        this.thread = thread;
    }

    private Logger logger = LoggerFactory.getLogger(DayStartThread.class);

    public void start() throws InterruptedException {
        Thread.sleep(2000);
        Runnable task = () -> {
         //当天更新录屏线程
         try {
             String nowDate =  DateUtils.parseDateToStr( DateUtils.YYYY_MM_DD,new Date());

              try {
                  thread.stopThread();
                  thread = null;
              }catch (Exception e){
                  logger.error(e.getMessage());
              }
             Thread.sleep(2000);
              this.thread =  new MouseMovementThread();
              new Thread(thread).start();
              logger.info("重启录屏--");


         }catch (Exception e){
             e.printStackTrace();
         }

        };
        executor.scheduleAtFixedRate(task,0, 1, TimeUnit.DAYS);

    }


}
